﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Caching;
using System.Text;
using System.Threading.Tasks;

namespace Bilgesoft.Framework.Server.Cache
{
    public class BilgeCache
    {
        private static BilgeCache _bilgeCache;
        private ObjectCache _cache;

        internal BilgeCache()
        {
            _cache = MemoryCache.Default;
        }

        public static BilgeCache Current
        {
            get
            {
                if (_bilgeCache == null)
                    _bilgeCache = new BilgeCache();
                return _bilgeCache;
            }
        }

        public void Put<T>(string key,T value) where T : class
        {
            CacheItemPolicy policy = new CacheItemPolicy();
            policy.AbsoluteExpiration = MemoryCache.InfiniteAbsoluteExpiration;
            _cache.Add(key, value, policy);
        }

        public T Get<T>(string key) where T:class
        {
            return (T)_cache.Get(key);
        }

    }
}
